home *** CD-ROM | disk | FTP | other *** search
- #ifndef __STD_ISTREAM__
- #define __STD_ISTREAM__
- #pragma option push -b -a4 -Vx- -Ve- -w-inl -w-aus -w-sig
-
- /***************************************************************************
- *
- * istream - Declarations for the Standard Library istreams
- *
- * $Id: istream,v 1.71 1996/09/24 19:17:11 smithey Exp $
- *
- ***************************************************************************
- *
- * (c) Copyright 1994, 1995 Rogue Wave Software, Inc.
- * ALL RIGHTS RESERVED *
- * The software and information contained herein are proprietary to, and
- * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
- * intends to preserve as trade secrets such software and information.
- * This software is furnished pursuant to a written license agreement and
- * may be used, copied, transmitted, and stored only in accordance with
- * the terms of such license and with the inclusion of the above copyright
- * notice. This software and information or any other copies thereof may
- * not be provided or otherwise made available to any other person.
- *
- * Notwithstanding any other lease or license that may pertain to, or
- * accompany the delivery of, this computer software and information, the
- * rights of the Government regarding its use, reproduction and disclosure
- * are as set forth in Section 52.227-19 of the FARS Computer
- * Software-Restricted Rights clause.
- *
- * Use, duplication, or disclosure by the Government is subject to
- * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
- * Technical Data and Computer Software clause at DFARS 252.227-7013.
- * Contractor/Manufacturer is Rogue Wave Software, Inc.,
- * P.O. Box 2328, Corvallis, Oregon 97339.
- *
- * This computer software and information is distributed with "restricted
- * rights." Use, duplication or disclosure is subject to restrictions as
- * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
- * Computer Software-Restricted Rights (April 1985)." If the Clause at
- * 18-52.227-74 "Rights in Data General" is specified in the contract,
- * then the "Alternate III" clause applies.
- *
- **************************************************************************/
-
- #ifndef __STD_RWCOMPILER_H__
- #include <stdcomp.h>
- #endif
-
- #include <ios>
- #include <ostream>
-
- #ifndef _RWSTD_NO_NAMESPACE
- namespace std {
- #endif
-
- extern istream _RWSTDExport cin;
-
- #ifndef _RWSTD_NO_WIDE_CHAR
- extern wistream _RWSTDExport wcin;
- #endif
-
- template<class charT, class traits>
- class _RWSTDExportTemplate basic_istream : virtual public basic_ios<charT, traits> {
-
- public:
-
- // for abbreviation
-
- typedef basic_istream<charT, traits> istream_type;
- typedef basic_ios<charT, traits> ios_type;
- typedef basic_streambuf<charT, traits> streambuf_type;
-
- typedef traits traits_type;
- typedef charT char_type;
- typedef _TYPENAME traits::int_type int_type;
- typedef _TYPENAME traits::pos_type pos_type;
- typedef _TYPENAME traits::off_type off_type;
-
-
-
- _EXPLICIT basic_istream(basic_streambuf<charT, traits> *sb);
- virtual ~basic_istream();
-
- class sentry
- {
- public:
-
- inline _EXPLICIT sentry(basic_istream<charT,traits>& stream,
- bool noskipws = 0)
- : stream_(stream)
- {
- #ifdef _RWSTD_MULTI_THREAD
- #ifndef _RWSTD_NO_EXCEPTIONS
- try {
- #endif
- if ( stream.rdbuf() )
- {
- _RWSTDGuard* tmp = new _RWSTDGuard(stream.rdbuf()->buffer_mutex_);
- if ( tmp )
- stream.istream_sentry_guard = tmp;
- else
- stream.istream_sentry_guard = 0;
- }
- #endif
-
- if(!(stream.good()))
- {
- stream.setstate(ios_base::failbit);
- ok_ = false;
- }
- else
- {
- if(stream.tie())
- stream.tie()->flush();
-
- if(!noskipws && (stream.flags() & ios_base::skipws))
- {
- int_type c;
-
- # ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
- const ctype<charT>& ct = use_facet< ctype<charT> >(stream.getloc());
- # else
- const ctype<charT>& ct = use_facet(stream.getloc(), (ctype<charT>*)0);
- # endif
-
- while((c = stream.rdbuf()->sgetc()),
- ( !traits::eq_int_type(c,traits::eof()) && ct.is(ct.space,c) ))
- {
- stream.rdbuf()->snextc();
- }
-
- if( traits::eq_int_type(c,traits::eof()) )
- {
- stream.setstate(ios_base::eofbit);
- }
- }
-
- if(!(stream.good()))
- {
- stream.setstate(ios_base::failbit);
- }
- else
- ok_ =true;
- }
-
- #ifdef _RWSTD_MULTI_THREAD
- #ifndef _RWSTD_NO_EXCEPTIONS
- }
-
- catch(...)
- {
- if ( stream.istream_sentry_guard )
- {
- delete stream.istream_sentry_guard;
- stream.istream_sentry_guard = 0;
- throw;
- }
- }
- #endif
- #endif
-
- }
-
- ~sentry() {
- #ifdef _RWSTD_MULTI_THREAD
- if ( stream_.istream_sentry_guard )
- {
- delete stream_.istream_sentry_guard;
- stream_.istream_sentry_guard = 0;
- }
- #endif
- }
-
- operator bool () { return ok_; }
-
- private:
-
- basic_istream<charT,traits>& stream_;
- bool ok_;
-
- };
-
- istream_type& operator>>(istream_type& (*pf)(istream_type&));
- istream_type& operator>>(ios_base& (*pf)(ios_base&));
- istream_type& operator>>(ios_type& (*pf)(ios_type&));
-
- #ifndef _RWSTD_NO_BOOL
- istream_type& operator>>(bool& n);
- #endif
- istream_type& operator>>(short& n);
- istream_type& operator>>(unsigned short& n);
- istream_type& operator>>(int& n);
- istream_type& operator>>(unsigned int& n);
- istream_type& operator>>(long& n);
- istream_type& operator>>(unsigned long& n);
- istream_type& operator>>(float& f);
- istream_type& operator>>(double& f);
- istream_type& operator>>(long double& f);
- #ifdef _RWSTD_LONG_LONG
- istream_type& operator>>(_RWSTD_LONG_LONG& n);
- #endif
- istream_type& operator>>(void*& p);
-
- istream_type& operator>>(streambuf_type& sb);
- istream_type& operator>>(streambuf_type *sb);
-
-
- int_type get()
- {
- ios_base::iostate err = 0;
-
- #ifndef _RWSTD_NO_EXCEPTIONS
- try {
- #endif
-
- _TYPENAME basic_istream<charT, traits>::sentry ipfx(*this,1);
-
- chcount_ = 0;
-
- if(ipfx) {
- int_type c = rdbuf()->sbumpc();
-
- if( traits::eq_int_type(c,traits::eof()) )
- {
- err = ios_base::eofbit | ios_base::failbit;
- }
- else
- {
- chcount_ = 1;
- return c;
- }
- }
-
- #ifndef _RWSTD_NO_EXCEPTIONS
- }
- #endif
-
- #ifndef _RWSTD_NO_EXCEPTIONS
- catch(...)
- {
- bool flag = false;
- try {
- this->setstate(ios_base::badbit);
- }
- catch( ios_base::failure ) { flag= true; }
- if ( flag ) throw;
- }
- #endif
-
- if ( err ) this->setstate(err);
-
- return traits::eof();
- }
-
-
- istream_type& get(char_type *s, streamsize n, char_type delim);
- istream_type& get(char_type *s, streamsize n)
- { return get(s,n,widen('\n')); }
-
- istream_type& get(char_type& c);
-
- istream_type& get(streambuf_type& sb, char_type delim);
- istream_type& get(streambuf_type& sb)
- { return get(sb,widen('\n')); }
-
- istream_type& getline(char_type *s, streamsize n, char_type delim);
- istream_type& getline(char_type *s, streamsize n)
- { return getline(s,n,widen('\n')); }
-
- istream_type& ignore(streamsize n = 1, int_type delim = traits::eof());
-
- istream_type& read(char_type *s, streamsize n);
-
- streamsize readsome(char_type *s, streamsize n);
-
- int peek();
-
- pos_type tellg();
-
- istream_type& seekg(pos_type pos)
- {
- ios_base::iostate err = 0;
-
- #ifndef _RWSTD_NO_EXCEPTIONS
- try {
- #endif
-
- if ( this->rdstate() & ios_base::eofbit )
- clear( this->rdstate() & ~ios_base::eofbit );
-
- #ifdef _RWSTD_MULTI_THREAD
- if ( rdbuf() )
- _RWSTDGuard guard(this->rdbuf()->buffer_mutex_);
- #endif
-
- if ( !this->bad() )
- if(rdbuf()->pubseekpos(pos, ios_base::in) == pos_type(off_type(-1)))
- err = ios_base::failbit;
-
- #ifndef _RWSTD_NO_EXCEPTIONS
- }
- #endif
-
- #ifndef _RWSTD_NO_EXCEPTIONS
- catch(...)
- {
- bool flag = false;
- try {
- this->setstate(ios_base::badbit);
- }
- catch( ios_base::failure ) { flag= true; }
- if ( flag ) throw;
- }
- #endif
-
- if ( err ) this->setstate(err);
-
- return *this;
- }
-
- int sync();
-
- #ifndef _RWSTD_NO_INT_TYPEDEF
- istream_type& seekg(off_type, ios_base::seekdir);
- #endif
-
- istream_type& putback(char_type c);
-
- istream_type& unget();
-
- streamsize gcount() const;
-
- #ifdef _RWSTD_MULTI_THREAD
- _RWSTDGuard *istream_sentry_guard;
- #endif
-
- protected:
- basic_istream( );
-
- private:
- streamsize chcount_;
- };
-
-
- /*
- *
- * Class basic_iostream
- *
- */
-
- template<class charT, class traits>
- class _RWSTDExportTemplate basic_iostream : public basic_istream<charT, traits>,
- public basic_ostream<charT, traits>
-
- {
-
- public:
-
- _EXPLICIT basic_iostream(basic_streambuf<charT, traits> *sb);
- virtual ~basic_iostream();
-
- protected:
-
- basic_iostream();
-
- };
-
- //
- // istream iterator.
- //
-
-
- #ifdef _RWSTD_NO_UNDEFINED_FRIEND
- template <class T, class charT, class traits, class Distance>
- class _RWSTDExportTemplate istream_iterator;
-
- template <class T, class charT, class traits, class Distance>
- bool _RWSTDExportTemplate operator==
- (const istream_iterator<T,charT,traits,Distance>& x,
- const istream_iterator<T,charT,traits,Distance>& y);
-
- #endif
-
-
- template <class T, class charT, class traits, class Distance>
- class _RWSTDExportTemplate istream_iterator : public iterator<input_iterator_tag,T,void>
- {
- friend bool _RWSTDExportTemplate operator== (const istream_iterator<T,charT,traits,Distance>& x,
- const istream_iterator<T,charT,traits,Distance>& y);
-
- protected:
-
- basic_istream<charT,traits>* stream;
- T value;
- bool end_marker;
-
- void read ()
- {
- end_marker = (*stream) ? true : false;
- if (end_marker) *stream >> value;
- end_marker = (*stream) ? true : false;
- }
-
- public:
- typedef T value_type;
- typedef charT char_type;
- typedef traits traits_type;
- typedef basic_istream<charT,traits> istream_type;
-
- istream_iterator () : stream(&cin), end_marker(false) {}
- istream_iterator (basic_istream<charT,traits>& s) : stream(&s) { read(); }
- istream_iterator ( const istream_iterator<T,charT,traits,Distance>& x )
- : stream(x.stream) , value(x.value) , end_marker(x.end_marker)
- { ; }
- const T& operator* () const { return value; }
- #ifndef _RWSTD_NO_NONCLASS_ARROW_RETURN
- const T* operator->() const { return &value; }
- #endif
- istream_iterator<T,charT,traits,Distance>& operator++ ()
- {
- read();
- return *this;
- }
- istream_iterator<T,charT,traits,Distance> operator++ (int)
- {
- istream_iterator<T,charT,traits,Distance> tmp = *this;
- read();
- return tmp;
- }
- };
-
- template <class T, class charT, class traits, class Distance>
- inline bool _RWSTDExportTemplate operator==
- (const istream_iterator<T,charT,traits,Distance>& x,
- const istream_iterator<T,charT,traits,Distance>& y)
- {
- return x.stream == y.stream && x.end_marker == y.end_marker ||
- x.end_marker == false && y.end_marker == false;
- }
-
- #ifndef _RWSTD_NO_NAMESPACE
- template <class T, class charT, class traits, class Distance>
- inline bool _RWSTDExportTemplate operator!=
- (const istream_iterator<T,charT,traits,Distance>& x,
- const istream_iterator<T,charT,traits,Distance>& y)
- {
- return !(x == y);
- }
- #endif
-
-
- template<class charT, class traits>
- basic_istream<charT, traits>&
- ws(basic_istream<charT, traits>& is);
-
- #ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
- typedef basic_istream<char> istream;
- #else
- typedef basic_istream<char, char_traits<char> > istream;
- #endif
-
- #ifndef _RWSTD_NO_WIDE_CHAR
- #ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
- typedef basic_istream<wchar_t> wistream;
- #else
- typedef basic_istream<wchar_t, char_traits<wchar_t> > wistream;
- #endif
- #endif
-
- #ifndef _RWSTD_NO_DEFAULT_TEMPLATES
- typedef basic_iostream<char> iostream;
- #else
- typedef basic_iostream<char, char_traits<char> > iostream;
- #endif
-
- #ifndef _RWSTD_NO_WIDE_CHAR
- #ifndef _RWSTD_NO_DEFAULT_TEMPLATES
- typedef basic_iostream<wchar_t> wiostream;
- #else
- typedef basic_iostream<wchar_t, char_traits<wchar_t> > wiostream;
- #endif
- #endif
-
-
- // charT and charT* extractors
-
- template<class charT, class traits>
- basic_istream<charT, traits>& _RWSTDExport
- operator>> ( basic_istream<charT, traits>&, charT& );
-
- template<class charT, class traits>
- basic_istream<charT, traits>& _RWSTDExport
- operator>> ( basic_istream<charT, traits>&, charT* );
-
-
- // signed and unsigned extractors
-
- #ifndef _RWSTD_NO_SIGNED_CHAR_IN_STREAMS
- template <class traits>
- basic_istream<char, traits>& _RWSTDExport
- operator>> ( basic_istream<char, traits>&, unsigned char& );
-
- template <class traits>
- basic_istream<char, traits>& _RWSTDExport
- operator>> ( basic_istream<char, traits>&, signed char& );
-
- template <class traits>
- basic_istream<char, traits>& _RWSTDExport
- operator>> ( basic_istream<char, traits>&, unsigned char* );
-
- template <class traits>
- basic_istream<char, traits>& _RWSTDExport
- operator>> ( basic_istream<char, traits>&, signed char* );
- #endif
-
- // String extractor and getline
-
- #ifndef _RWSTD_NO_NAMESPACE
- }
- namespace __rwstd {
- #endif
-
- template <class streamT, class stringT, class traits>
- streamT& rw_extract_string(streamT& is, stringT& s, traits);
-
- #ifndef _RWSTD_NO_NAMESPACE
- }
- namespace std {
- #endif
-
- #ifndef _MSC_VER
- template<class charT, class traits, class Allocator>
- inline basic_istream<charT, traits>&
- _RWSTDExportTemplate operator>> (basic_istream<charT,traits>& is,
- basic_string<charT,traits,Allocator>& s)
- {
- return __RWSTD::rw_extract_string(is,s,traits());
- }
- #else
- inline istream& _RWSTDExport operator>> (istream& is, string& s)
- {
- return __RWSTD::rw_extract_string(is,s,char_traits<char>());
- }
- #ifndef _RWSTD_NO_WIDE_CHAR
- inline wistream& _RWSTDExport operator>> (wistream& is, wstring& s)
- {
- return __RWSTD::rw_extract_string(is,s,char_traits<wchar_t>());
- }
- #endif /* _RWSTD_NO_WIDE_CHAR */
- #endif /* _MSC_VER */
-
- template<class charT, class traits, class Allocator>
- basic_istream<charT, traits>& _RWSTDExportTemplate
- getline( basic_istream<charT, traits>&,
- basic_string<charT, traits, Allocator>&,
- charT delim );
-
- template<class charT, class traits, class Allocator>
- inline basic_istream<charT, traits>& _RWSTDExportTemplate
- getline( basic_istream<charT, traits>& is,
- basic_string<charT, traits, Allocator>& str )
- { return getline(is,str,is.widen('\n')); }
-
-
- #ifndef _RWSTD_NO_NAMESPACE
- }
- #endif
-
- #ifdef _RWSTD_COMPILE_INSTANTIATE
- #include <istream.cc>
- #endif
-
- #pragma option pop
- #endif /* __ISTREAM__ */
-